/**
 * 
 */
package com.ailk.evaluation.manager;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Component;

import com.ailk.evaluation.common.OutputResult;
import com.ailk.evaluation.sql.ParameterizedSQLFactory;
import com.ailk.evaluation.sql.SQLFactoryInterface;



/**
 * @author DerekHong
 *
 */
@Component("deleteManager")
public class DeleteManager {
	@Resource(name="jdbcOperation")
	protected JdbcOperation jdbc;
	
	/* (non-Javadoc)
	 * @see com.anhorn.backyard.service.ProxyService#delete(javax.servlet.http.HttpServletRequest)
	 */
	public OutputResult delete(String tableName, HttpServletRequest request) {
		Map<String, Object> params = ParameterUtils.parseRequest(request);
		return delete(tableName, params);
	}
	
	/**
	 * @param string
	 * @param params
	 */
	public OutputResult delete(String tableName, Map<String, Object> params) {
		SQLFactoryInterface sql = new ParameterizedSQLFactory(tableName, ParameterUtils.parseParameters(params));
		return jdbc.delete(sql.genDelete());		
	}
	
	public OutputResult deleteWhenWhere(String tableName, Map<String, Object> params) {
		SQLFactoryInterface sql = new ParameterizedSQLFactory(tableName, ParameterUtils.parseParameters(params));
		if (sql.haveWhereCondtion()) {
			return jdbc.delete(sql.genDelete());	
		}
		return new OutputResult();				
	}
}
